Socket
Socket
Sign inDemoInstall

require-all

Package Overview
Dependencies
Maintainers
4
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require-all

An easy way to require all files within a directory.


Version published
Weekly downloads
146K
decreased by-7.55%
Maintainers
4
Weekly downloads
 
Created

What is require-all?

The require-all npm package is a utility that allows you to require all files within a directory. This can be particularly useful for loading all modules in a directory without having to require each one individually.

What are require-all's main functionalities?

Require all files in a directory

This feature allows you to require all files in a specified directory. In this example, all files in the 'controllers' directory will be required and stored in the 'controllers' object.

const requireAll = require('require-all');
const controllers = requireAll(__dirname + '/controllers');

Filter files by extension

This feature allows you to filter the files to be required by their extension. In this example, only JavaScript files in the 'controllers' directory will be required.

const requireAll = require('require-all');
const jsFiles = requireAll({
  dirname: __dirname + '/controllers',
  filter: /(.+\.js)$/
});

Recursive directory loading

This feature allows you to recursively require all files in a directory and its subdirectories. In this example, all files in the 'modules' directory and its subdirectories will be required.

const requireAll = require('require-all');
const modules = requireAll({
  dirname: __dirname + '/modules',
  recursive: true
});

Map filenames to module names

This feature allows you to map filenames to module names. In this example, the '.js' extension is removed from the filenames when they are used as keys in the 'controllers' object.

const requireAll = require('require-all');
const controllers = requireAll({
  dirname: __dirname + '/controllers',
  map: function (name, path) {
    return name.replace(/\.js$/, '');
  }
});

Other packages similar to require-all

FAQs

Package last updated on 03 Jul 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc